package com.xjl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xjl.service.UserService;
import com.xjl.service.impl.UserServiceImpl;
@WebServlet("/updateuser.do")
public class UpDateUserServlet extends HttpServlet {
	UserService us = new UserServiceImpl();
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//设置请求编码格式
		req.setCharacterEncoding("utf-8");
		//设置响应编码格式
		resp.setContentType("text/html;utf-8");
		int oper = Integer.parseInt( req.getParameter("oper")) ;
		if(oper==1){
			DeleteUserService(req,resp);
			return;
		}else{
			req.setAttribute("flag2", "网络异常，请稍后再试！");
			req.getRequestDispatcher("showuser").forward(req, resp);;
		}
	}
	
	public void DeleteUserService(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
		int uid = Integer.parseInt(req.getParameter("uid"));
		int index = us.DeleteUserByIdService(uid);
		if(index==1){
			req.setAttribute("flag2", "删除成功！");
		}else{
			req.setAttribute("flag2", "网络异常，请稍后再试！");
		}
		req.getRequestDispatcher("showuser.do").forward(req, resp);;
	}
	
}
